home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / MacApp Documentation / MacApp AppleLink Messages / MacApp.Tech$ Oct 89 / Z0137-TDialogView Bug Fix-Oct89 < prev    next >
Encoding:
Text File  |  1989-10-20  |  6.9 KB  |  219 lines  |  [TEXT/GEOL]

  1. Item    4929214                         19-Oct-89        12:29
  2.  
  3. From:   D2086                           Efficient Field Svc, C Faith,PRT
  4.  
  5. To:     APPLE.BUGS                      Apple Bugs Reporting
  6.         MACAPP.TEST                     MacApp SQA Team
  7.         MACAPP.TECH$                    MACAPP Tech
  8.  
  9. Sub:    TDialogView Bug Fixes (long)
  10.  
  11. This is an update on problems I have been having with TDialogView and the
  12. solution I have devised.
  13.  
  14. There are 3 bugs involved:
  15.  
  16. 1) a default Control does not Flash when return, enter, cancel or Esc is
  17. pressed unless the Control dismisses.
  18.  
  19. 2) the application must be aware of which Controls are default and cancel (if
  20. the dialog has a DoChoice override) because the itsChoice is not the same as if
  21. the Control had been hit with a mouse it is mDefaultKey or mCancelKey.
  22. This means that changing just the resource file to reflect a different default
  23. key will often not work.
  24.  
  25. 3) Using DeselectCurrentEditText as a method yourself in a TDialogView Override
  26. can cause TEditText.DoMouseCommand to bomb.  This is because the method does
  27. not change gTarget and TEditText.DoMouseCommand assumes that it is already
  28. selected if gTarget is equal to SELF, (which is not the case after a call to
  29. DeselectCurrentEditText since it did not change gTarget).
  30.  
  31. The solution I have devised to the first 2 problems is related.  I tried to
  32. make the actions of TDialogView.DoKeyCommand treat the item just as if it had
  33. been pressed with a mouse, I passed fDefChoice instead of mDefaultKey etc.  The
  34. only problem with this is that TDialogView.DoChoice flashes the dismisser when
  35. it gets a mDefaultKey but not when its gets the mButtonHit for example.  This
  36. is because TrackControl has already flashed the button by the time it gets to
  37. DoChoice with a mButtonHit.
  38.  
  39. Recall that bug 1 above also involves flashing default controls, so to fix the
  40. flashing I simply flash the control in TDialogView.DoKeyCommand whenever a
  41. default or cancel key is pressed. This means that there is no longer any reason
  42. to distinguish between mButtonHit and mDefaultKey as they will already have
  43. been flashed by the time they get to the DoChoice method, and DismissDialog
  44. will no longer need to flash.  Hence I removed the flashDismisser parameter and
  45. code completely from DismissDialog.
  46.  
  47. The third bug is perhaps a little less resolved.  I am not sure exactly what
  48. the best solution is.  I have changed DeselectCurrentEditText to change the
  49. target to the dialog or SELF for now and this works fine.  Perhaps it should be
  50. set to something else ?.
  51.  
  52. Hope Someone finds this useful,
  53.  
  54. Curtis
  55.  
  56. The changes I have made are as follows:
  57.  
  58. {$S DlgClose}
  59. { +++ Changed the interface for DismissDialog removed flashDismisser reference
  60. }
  61. PROCEDURE TDialogView.DismissDialog(dismisser: IDType);
  62.  
  63.    BEGIN
  64.    IF NOT fDismissed THEN
  65.    IF CanDismiss(dismisser) THEN
  66.    BEGIN
  67.    fDismissed := TRUE;
  68.    fDismisser := dismisser;
  69.    END
  70.    ELSE
  71.    Failure(noErr, 0);  { Silent failure }
  72.    END;
  73.  
  74. {------------------------------------------------------------------------------
  75. --------------------}
  76. PROCEDURE TDialogView.DoChoice(origView: TView; itsChoice: INTEGER); OVERRIDE;
  77.  
  78.    BEGIN
  79.    CASE itsChoice OF
  80.    mEditTextHit:
  81.    BEGIN
  82.    {$IFC qDebug}
  83.    IF NOT Member(origView, TEditText) THEN
  84.    ProgramBreak('Got mEditTextHit on non-TEditText view.')
  85.    ELSE
  86.    {$ENDC}
  87.    DoSelectEditText(TEditText(origView), False);
  88.    END;
  89.  
  90.    { +++ Removed special case for mDefaultKey, mCancelKey }
  91.  
  92.    OTHERWISE
  93.    IF Member(origView, TControl) & TControl(origView).fDismissesDialog THEN
  94.    DismissDialog(origView.fIdentifier)
  95.    ELSE
  96.    INHERITED DoChoice(origView, itsChoice);
  97.    END;
  98.    END;
  99.  
  100. {------------------------------------------------------------------------------
  101. --------------------}
  102. {$S DlgRes}
  103.  
  104. FUNCTION TDialogView.DoCommandKey(ch: CHAR; VAR info: EventInfo): TCommand;
  105. OVERRIDE;
  106.    VAR
  107.    cancelView: TView;
  108.  
  109.    BEGIN
  110.    IF IsViewEnabled & (ch = '.') & (LONGINT(fCancelItem) <>
  111. LONGINT(kNoIdentifier)) THEN
  112.    BEGIN { +++ Changed below to pass fDefChoice for Controls }
  113.    cancelView := FindSubView(fCancelItem);
  114.    IF (cancelView <> NIL) & Member(cancelView, TControl) THEN
  115.    BEGIN
  116.    TControl(cancelView).Flash;
  117.    DoChoice(cancelView, TControl(cancelView).fDefChoice);
  118.    END
  119.    ELSE
  120.    DoChoice(cancelView, mCancelKey);
  121.    DoCommandKey := gNoChanges;
  122.    END
  123.    ELSE
  124.    DoCommandKey := INHERITED DoCommandKey(ch, info);
  125.    END;
  126.  
  127. {------------------------------------------------------------------------------
  128. --------------------}
  129. {$S DlgRes}
  130.  
  131. FUNCTION TDialogView.DoKeyCommand(ch: CHAR; aKeyCode: INTEGER;
  132.    VAR info: EventInfo): TCommand; OVERRIDE;
  133.    VAR
  134.    defaultView:TView;
  135.    cancelView: TView;
  136.  
  137.    BEGIN
  138.    { If we get this far, nobody's handled the Tab, Enter, or Return keys, so we
  139. will  }
  140.    DoKeyCommand := gNoChanges;
  141.    IF IsViewEnabled THEN
  142.    CASE ch OF
  143.    chEscape:
  144.    IF aKeyCode = kClearVirtualCode THEN
  145.    DoKeyCommand := INHERITED DoKeyCommand(ch, aKeyCode, info)
  146.    ELSE IF LONGINT(fCancelItem) <> LONGINT(kNoIdentifier) THEN
  147.    BEGIN { +++ Changed below to pass fDefChoice for Controls }
  148.    cancelView := FindSubView(fCancelItem);
  149.    IF (cancelView <> NIL) & Member(cancelView, TControl) THEN
  150.    BEGIN
  151.    TControl(cancelView).Flash;
  152.    DoChoice(cancelView, TControl(cancelView).fDefChoice);
  153.    END
  154.    ELSE
  155.    DoChoice(cancelView, mCancelKey);
  156.    END;
  157.    chTab:
  158.    Tab(info.theShiftKey);
  159.    chEnter, chReturn:
  160.    IF LONGINT(fDefaultItem) <> LONGINT(kNoIdentifier) THEN
  161.    BEGIN { +++ Changed below to pass fDefChoice for Controls }
  162.    defaultView := FindSubView(fDefaultItem);
  163.    IF (defaultView <> NIL) & Member(defaultView, TControl) THEN
  164.    BEGIN
  165.    TControl(defaultView).Flash;
  166.    DoChoice(defaultView, TControl(defaultView).fDefChoice);
  167.    END
  168.    ELSE
  169.    DoChoice(defaultView, mDefaultKey);
  170.    END;
  171.    OTHERWISE
  172.    DoKeyCommand := INHERITED DoKeyCommand(ch, aKeyCode, info);
  173.    END
  174.    ELSE
  175.    DoKeyCommand := INHERITED DoKeyCommand(ch, aKeyCode, info);
  176.    END;
  177.  
  178. {------------------------------------------------------------------------------
  179. --------------------}
  180. FUNCTION TDialogView.DeselectCurrentEditText: BOOLEAN;
  181.  
  182.    VAR
  183.    validateResult: LONGINT;
  184.    itsWindow:  TWindow;
  185.  
  186.    BEGIN
  187.    DeselectCurrentEditText := TRUE;
  188.  
  189.    IF fCurrentEditText <> NIL THEN
  190.    BEGIN
  191.    { Commit the last command to prevent undo from applying to the wrong edit
  192. text,
  193.      and to ensure that all changes are made before validating. }
  194.    IF (gLastCommand <> NIL) & (gLastCommand.fView = fTEView) THEN
  195.    gApplication.CommitLastCommand;
  196.  
  197.    validateResult := fCurrentEditText.Validate;
  198.    IF validateResult = kValidValue THEN
  199.    BEGIN
  200.    fCurrentEditText.StopEdit;
  201.    fCurrentEditText := NIL;{ No edit text is selected }
  202.     { +++ Added this to change target }
  203.    itsWindow := GetWindow; { Set the window's target to self }
  204.    IF itsWindow <> NIL THEN
  205.    itsWindow.SetTarget(SELF)
  206.    ELSE
  207.    gApplication.SetTarget(gApplication);
  208.    END
  209.    ELSE
  210.    BEGIN
  211.    CantDeselect(fCurrentEditText, validateResult);
  212.    DeselectCurrentEditText := False;
  213.    END;
  214.    END;
  215.    END;
  216.  
  217.  
  218.  
  219.